﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.Linq.Expressions;
using System.ServiceModel.Web;
using System.Web;

namespace WcfDataServicesLibrary
{
    public class NorthwindService : DataService<NorthwindEntities>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
			config.SetEntitySetAccessRule("*", EntitySetRights.All);
			config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
		}

		#region New Service Operations



		#endregion

		#region Service Operations

		//[WebGet]
		//public List<CustomerOrderHistory_Result> CustomerOrderHistory2(string customerId)
		//{
		//    using (var context = new NorthwindEntities())
		//    {
		//        var result = context.CustomerOrderHistory(customerId).ToList();
		//        return result;
		//    }
		//}

		//[WebGet]
		//public String CustomerOrderHistory(string customerId)
		//{
		//    return "LOL";
		//    //using (var context = new NorthwindEntities())
		//    //{
		//    //    var result = context.CustomerOrderHistory(customerId).AsQueryable();
		//    //    return result;
		//    //}
		//}

		//[QueryInterceptor("Customers")]
		//public Expression<Func<Customer, Boolean>> OnQueryCustomers()
		//{
		//    return c => String.Equals(c.Country, "USA");
		//} 

		//[ChangeInterceptor("Products")]
		//public void OnChangeProducts(Product product, UpdateOperations operations)
		//{
		//    if(operations == UpdateOperations.Add || operations == UpdateOperations.Change)
		//    {
		//        if(product.Discontinued)
		//        {
		//            throw new DataServiceException(String.Format("Modifications are not allowed ont discontinued product: ID: {0} Name: {1}", product.ProductID, product.ProductName));
		//        }
		//    }
		//    else if(operations == UpdateOperations.Delete)
		//    {
		//        throw new DataServiceException(String.Format("Deletion is not allowed on discontinued product: ID: {0} Name: {1}", product.ProductID, product.ProductName));
		//    }
		//}

		#endregion
	}
}
